import request from '@/utils/request'
import { Loading } from "element-ui";


export const apiRequest = async (apiMethod = "", apiUrl = "", data = {},
	isLoading = true) => {
	// 请求类型
	let requestType = apiMethod.toLowerCase();

	//加载loading
	const loadingInstance = Loading.service({
		fullscreen: isLoading,
		text: "Loading",
		spinner: "el-icon-loading",
		background: "rgba(0, 0, 0, 0.7)",
	});

	if (requestType && requestType === 'get') {
		var res = await request({
			url: apiUrl,
			method: 'get'
		})
	}

	if (requestType && requestType === "delete") {
		var res = await request({
			url: apiUrl,
			method: "delete"
		})
	}

	if (requestType && requestType === 'post') {
		var res = await request({
			url: apiUrl,
			method: 'post',
			data
		})
	}

	//关闭loading
	loadingInstance.close();


	return res;
}